﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Text.RegularExpressions;
using Microsoft.IdentityModel.Claims;

namespace BLL
{
    public static class Helpers
    {
        public static string GetNameIdentifier(this IIdentity identity)
        {
            var claimsIndentity = identity as ClaimsIdentity;

            if (claimsIndentity == null)

                return string.Empty;



            var providerQuery = from c in claimsIndentity.Claims

                                where c.ClaimType == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier"

                                select c.Value;

            var provider = providerQuery.FirstOrDefault();
            return provider != null ? Regex.Replace(provider, @"[\ /?#]", "") : "NO_USER";
        }
    }
}
